import 'package:flutter/material.dart';

class QuantityCounter extends StatelessWidget {
  final int quantity;
  final Function(int) onTap;

  QuantityCounter({
    Key key,
    @required this.quantity,
    @required this.onTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        border: Border.all(color: Colors.grey),
        borderRadius: BorderRadius.circular(5),
      ),
      width: 90,
      height: 23,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          GestureDetector(
            child: Container(
              alignment: Alignment.center,
              decoration: BoxDecoration(
                border: Border(
                  right: BorderSide(color: Colors.grey),
                ),
              ),
              width: 23,
              child: Text(
                '-',
                style: TextStyle(color: Colors.grey),
              ),
            ),
            onTap: quantity <= 1 ? null : () => onTap(quantity - 1),
          ),
          Text(
            '$quantity',
            style: TextStyle(color: Colors.grey),
          ),
          GestureDetector(
            child: Container(
              alignment: Alignment.center,
              decoration: BoxDecoration(
                border: Border(
                  left: BorderSide(color: Colors.grey),
                ),
              ),
              width: 23,
              child: Text(
                '+',
                style: TextStyle(color: Colors.grey),
              ),
            ),
            onTap: () => onTap(quantity + 1),
          ),
        ],
      ),
    );
  }
}
